import request from '@/utils/request'

export const permissionApi = {
  // 创建权限
  createPermission: (permission) => {
    return request.post('/api/permissions', permission)
  },

  // 获取权限详情
  getPermission: (id) => {
    return request.get(`/api/permissions/${id}`)
  },

  // 更新权限
  updatePermission: (id, permission) => {
    return request.put(`/api/permissions/${id}`, permission)
  },

  // 删除权限
  deletePermission: (id) => {
    return request.delete(`/api/permissions/${id}`)
  },

  // 获取权限列表
  getPermissions: (page = 1, size = 10) => {
    return request.get('/api/permissions', {
      params: { page, size }
    })
  },

  // 获取权限树
  getPermissionTree: () => {
    return request.get('/api/permissions/tree')
  },

  // 为权限分配角色
  assignRole: (permissionId, roleId) => {
    return request.post(`/api/permissions/${permissionId}/roles`, {
      permissionId,
      roleId
    })
  },

  // 移除权限角色
  removeRole: (permissionId, roleId) => {
    return request.delete(`/api/permissions/${permissionId}/roles/${roleId}`)
  }
} 